package ua.com.stormlabs.tiny.licenseserver.storage;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.DefaultResourceLoader;

import java.io.IOException;

/**
 * @author Denis Bondarenko
 * @version 1.0 Apr 28, 2010
 */
class SqlLoader {

    private final static Logger log = LoggerFactory.getLogger(SqlLoader.class);

    private static final DefaultResourceLoader resourceLoader = new DefaultResourceLoader();

    private SqlLoader() {
    }

    public static String load(String scriptName) {
        try {
            return IOUtils.toString(resourceLoader.getResource(scriptName).getInputStream());
        } catch (IOException e) {
            String msg = "Failed to load resource '" + scriptName + "'. Error: " + e;
            log.error(msg, e);
            throw new IllegalArgumentException(msg, e);
        }
    }
}
